<?php
// 应用公共文件
if(!function_exists('successes')){
    function successes($msg,$data=[]){
        return json([
            'code'=>200,
            'msg'=>$msg,
            'data'=>$data
        ]);
    }
}
if(!function_exists('fail')){
    function fail($msg,$data=[]){
        return json([
            'code'=>201,
            'msg'=>$msg,
            'error'=>$data
        ]);
    }
}
if(!function_exists('jsons')){
    function jsons($code,$msg,$data=[]){
        return json([
            'code'=>$code,
            'msg'=>$msg,
            'data'=>$data
        ]);
    }
}

//密码加盐
if(!function_exists('passwordEncrypt')){
    function passwordEncrypt($password){
        $salt='1910a';
        $password=md5($salt.$password.$salt);
        return $password;
    }
}

//父级分类
if(!function_exists('types')){
    function types($data,$pid=0){
        $arr=[];
        foreach ($data as $val){
            if($val['pid']==$pid){
                $arr[$val['id']]=$val;
                $arr[$val['id']]['children']=types($data,$val['id']);
            }
        }
        return $arr;
    }
}